var pop;

$(document).ready(function() {
	init();
	init3();
});

function showCart(e){
	var html = "动画还没做好，点击跳到购物车";//插入代码读取session
	tooltips.showtips(e, html);
}

function showMessage(e, msg){
	tooltips3.showtips3(e, msg);
	setTimeout("$('#tipdiv3').animate({left:'-200px', opacity:0.1}, 800)", 3000);
}

function inputFocus(){
	if(document.getElementById("searchKeyword").value == "请输入关键词..."){
		$("#searchKeyword").removeClass("gray");
		$("#searchKeyword").addClass("black");
		document.getElementById("searchKeyword").value="";
	}
}

function inputBlur(){
	if(document.getElementById("searchKeyword").value == ""){
		$("#searchKeyword").removeClass("black");
		$("#searchKeyword").addClass("gray");
		document.getElementById("searchKeyword").value="请输入关键词...";
	}
}

function showLogin() {
	var strHtml = '\
		<div class="loginDetail">\
			<div class="top">会员登录</div>\
			<div class="middle">\
				<form onsubmit="return false;">\
					<table>\
						<tr>\
							<th>用户名：</th>\
							<td>\
								<input type="text" id="signInName" name="signInName" class="formText" onblur="isloginUsername(this.value)"/>\
							</td>\
						</tr>\
					<tr ><th></th><td><div id="checkloginusername" class="item_error"></div></td></tr>\
						<tr>\
							<th>密&nbsp;&nbsp;&nbsp;码：</th>\
							<td>\
								<input type="password" id="password" name="password" class="formText" onblur="isloginPassword(this.value)"/>\
							</td>\
						</tr>\
			<tr ><th></th><td><div id="checkloginpassword" class="item_error"></div></td></tr>\
						<tr>\
							<th>验证码：</th>\
							<td>\
								<input type="text" id="loginCaptcha" name="j_captcha" class="formTextS" onblur="isloginCaptcha(this.value)"/>\
								<img id="loginCaptchaImage" src="page/front/image.jsp" title="点击更换验证码" onclick="loadloginimage();"/>\
							</td>\
						</tr>\
			<tr ><th></th><td><div id="checklogincaptcha" class="item_error"></div></td></tr>\
						<tr>\
							<th>&nbsp;</th>\
							<td>\
								<span class="warnIcon">&nbsp;</span><a href="">忘记了密码? 点击找回!</a>\
							</td>\
						</tr>\
						<tr>\
							<th>&nbsp;</th>\
							<td>\
								<input type="submit" value="登 录" hidefocus="true" class="submitButton" onclick="login();" />\
								<input type="reset" value="清空" hidefocus="true" class="submitButton" />\
							</td>\
						</tr>\
					</table>\
					<p id="error"></p>\
				</form>\
			</div>\
			<div class="bottom"></div>\
		</div>';
	pop = new Popup({contentType:2, isReloadOnClose:false, width:500, height:300});
	pop.setContent("contentHtml",strHtml);
	//pop.setContent("title","会员登录");
	pop.build();
	pop.show();
}

function showRegister() {
	var strHtml = '\
		<div class="loginDetail">\
			<div class="top">会员注册</div>\
			<div class="middle">\
				<form onsubmit="return false;">\
					<table>\
						<tr>\
							<th>用&ensp;户&ensp;名：</th>\
							<td>\
								<input type="text" id="RegisterUsername" name="signInName" class="formText" onblur="isregisterUsername(this.value)"/>\
							</td>\
						</tr>\
		<tr ><th></th><td><div id="checkregisterusername" class="item_error"></div></td></tr>\
						<tr>\
							<th>密&emsp;&emsp;码：</th>\
							<td>\
								<input type="password" id="RegisterPassword" name="password" class="formText" onblur="isregisterPassword(this.value)"/>\
							</td>\
						</tr>\
		<tr ><th></th><td><div id="checkregisterpassword" class="item_error"></div></td></tr>\
						<tr>\
							<th>密码确认：</th>\
							<td>\
								<input type="password" id="RegisterPasswordCheck" class="formText" onblur="isregisterPasswordconfirm(this.value)"/>\
							</td>\
						</tr>\
		<tr ><th></th><td><div id="checkregisterpasswordconfirm" class="item_error"></div></td></tr>\
						<tr>\
							<th>验&ensp;证&ensp;码：</th>\
							<td>\
								<input type="text" id="RegisterCaptcha" class="formTextS" onblur="isregisterCaptcha(this.value)"/>\
								<img id="RegisterCaptchaImage" src="page/front/image.jsp" title="点击更换验证码" onclick="loadregisterimage()"/>\
							</td>\
						</tr>\
		<tr ><th></th><td><div id="checkregistercaptcha" class="item_error"></div></td></tr>\
						<tr>\
							<th>&nbsp;</th>\
							<td>\
								<input type="submit" value="注册" hidefocus="true" class="submitButton" onclick="register();" />\
								<input type="reset" value="清空" hidefocus="true" class="submitButton" />\
							</td>\
						</tr>\
					</table>\
					<p id="error"></p>\
				</form>\
			</div>\
			<div class="bottom"></div>\
		</div>';  
	pop = new Popup({contentType:2, isReloadOnClose:false, width:500, height:300});
	pop.setContent("contentHtml",strHtml);
	//pop.setContent("title","会员注册");
	pop.build();
	pop.show();
}

function login() {
	if (verifylogin()) {
		var url = "userLogin.do";
		var params = {signInName:$("#signInName").val(), password:$("#password").val(), rand:$("#loginCaptcha").val()};
		$.post(url, params, loginCallback);
	}
}

function loginCallback(data, e) {
	if (data == "success") {
		pop.close();
		showMessage(e, "登录成功");
		setTimeout("window.location.reload();", 3800);
	} else {
		$("#error").html(data);
	}
}

function register() {
	if (verifyregister()) {
		var url = "userRegister.do";
		var params = {signInName:$("#RegisterUsername").val(), password:$("#RegisterPasswordCheck").val(), rand:$("#RegisterCaptcha").val()};
		$.post(url, params, registerCallback);
	}
}

function registerCallback(data, e) {
	if (data == "success") {
		pop.close();
		showMessage(e, "注册成功");
		setTimeout("window.location.reload();", 3800);
	} else {
		$("#error").html(data);
	}
}
